/*
   @Copyright:LibreOJ
   @Author:   tjyemail
   @Problem:  https://loj.ac/problem/119
   @Language: C++
   @Datetime: 20-08-13 15:07
   */
// dijkstra, 27ms

#include <bits/stdc++.h>
using namespace std;

#define VERTEX 2505
int dists[VERTEX];
bool visited[VERTEX];
//int path[VERTEX];
vector<pair<int,int> > edges[VERTEX]; // adjacency cell : vertex, cost

void dijkstra(int v, int s, int t) {
	for(dists[s]=0; s!=t; ) {
		// update dists from s's adjacency
		visited[s] = true;
		for(const auto &p:edges[s]) {
			if (dists[p.first]==0 || dists[p.first]>dists[s]+p.second) {
				dists[p.first] = dists[s] + p.second;
				//path[p.first] = s; // record path p.first <- s
			}
		}
		// find next min dist vertex s
		int m = INT_MAX;
		for(int i=0; i++<v;)
			if (!visited[i] && dists[i] && dists[i]<m)
				m = dists[s=i];
	}
	printf("%d\n", dists[t]);
}

int main()
{
	int v, e, s, t, a, b, c; // vertex edge, start -> target
	scanf("%d %d %d %d", &v, &e, &s, &t);
	for(int i=0; i++<e; ) {
		scanf("%d %d %d", &a, &b, &c); // a->b, cost
		edges[a].push_back({b, c});
		edges[b].push_back({a, c});
	}
	dijkstra(v, s, t);
	// shortest path t <- ... <- s
	//for(printf("%d", a); a!=s; printf("<-%d", a=path[a]));
	//printf("\n");
	return 0;
}
